//
//  ZDHotViewController.m
//  1012GiftTips
//
//  Created by Apple on 15/10/15.
//  Copyright © 2015年 itcast. All rights reserved.
//

#import "ZDHotViewController.h"
#import "ZDCollectionViewCell.h"
#import "ZDJumpViewController.h"

#define ZDItemWidth 150
#define ZDItemHight 200

@interface ZDHotViewController () <UICollectionViewDataSource, UICollectionViewDelegate>

@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;


@end

@implementation ZDHotViewController


- (void)viewDidLoad
{
    [super viewDidLoad];
    
//    self.title = @"热门";
    
    self.collectionView.backgroundColor = ZDColor(235, 235, 242);
    
    //注册
    [self.collectionView registerNib:[UINib nibWithNibName:NSStringFromClass([ZDCollectionViewCell class]) bundle:nil] forCellWithReuseIdentifier:NSStringFromClass([ZDCollectionViewCell class])];
    
    
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    
    self.collectionView.collectionViewLayout = layout;
    
    layout.minimumLineSpacing = 0;
    layout.minimumInteritemSpacing = 6;
    layout.itemSize = CGSizeMake((ZDScreenSize.width - 30) * 0.5, ZDItemHight);   //item的宽度根据屏幕size动态调整
    layout.sectionInset = UIEdgeInsetsMake(5, 10, 5, 10);
    
//    ZDLog(@"%@", NSStringFromCGRect(self.collectionView.frame));
}


#pragma mark - UICollectionViewDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    //由模型决定
    return 20;
}


- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
//    ZDCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([ZDCollectionViewCell class]) forIndexPath:indexPath];
    
    ZDCollectionViewCell *cell = [ZDCollectionViewCell collectionViewCell:collectionView andIndexPath:indexPath];
    
    //模型赋值
    
    return cell;
}



#pragma mark - UICollectionViewDelegate
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    //取出对应模型赋值
    
    ZDJumpViewController *jumpVc = [[ZDJumpViewController alloc] init];
    
    [self.navigationController pushViewController:jumpVc animated:YES];
}


@end
